<template>
    <div class="fl_jhb" :class="{'ishshow':ishshow}">
        <img :src="imgsrc" class="jhb" @click="callApp"/>
        <img class="close_jhb" src="../assets/images/close-icon.png" @click="closejhb">
    </div>
</template>

<script>
    import qs from "querystring"

    export default {
        props: {
            jhb_info: {
                type: Object,
                default: function () {
                    return {};
                }
            },
            wakeupParam: {
                type: Object,
                default: function () {
                    return {
                        contentType: 6,
                        contentParam: "",
                        infoParams: {}
                    }
                }
            }
        },
        data: function () {
            return {
                ishshow: false,
                imgsrc:require("../assets/images/hb.png"),
                ishas:0
            }
        },
        mounted: function () {
            let that = this;
         //   console.log(this.jhb_info.contentType==2&&this.jhb_info.channelid!="")
            //优先显示播放器挂脚的活动，如果不存在，则显示捡红包
            if(this.jhb_info.contentType==2&&this.jhb_info.channelid){
            this.axios.post(
                interbaseUrl + "setsail/external/externalService?service=getChannelRealtimeMsgList",//获得播放器挂脚
                qs.stringify({
                    params: JSON.stringify({
                        programId: this.jhb_info.contentId,
                        channelId: this.jhb_info.channelid,
                        type:1
                    }),
                    apiVersion: process.env.VUE_APP_SERVER_VER
                })
            ).then((response) => {
                console.log(response.data.data.rows.length)
                if(response.data.data.rows.length==0){
                    that.ifjhb();
                }else{
                  for(var i=0;i<response.data.data.rows.length;i++){
                      if(response.data.data.rows[i].type!=5){//类型为5的是公告，不显示
                        that.ishas==1;
                        that.imgsrc=response.data.data.rows[i].picUrl;
                        that.ishshow=true;
                        break;
                      }
                  }
                    if(that.ishas==0){
                        that.ifjhb();
                    }
                }
            })
            }

            that.ifjhb();
        },
        methods: {
            closejhb: function () {
                this.ishshow = false;
            },
            callApp: function () {
                // console.log(JSON.stringify(this.wakeupParam, undefined, 2));
          /*      let r = confirm("该活动需要打开【扬帆】app后登陆参与，确认打开参与吗？");
                if (r == false) {
                    return false;
                } else if (r == true) {
                    openDownPage(this.wakeupParam.contentType, this.wakeupParam.contentParam, this.wakeupParam.infoParams);
                }
*/

                let that=this;
                that.$dialog.confirm('该活动需要打开【扬帆】app后登陆参与，确认打开参与吗？',{
                    okText: '确定',  // 本地化确认按钮文字提示内容
                    cancelText: '取消',  //本地化关闭按钮文字提示内容
                })
                    .then(function () {
                        // 点击确定执行
                        openDownPage(that.wakeupParam.contentType, that.wakeupParam.contentParam, that.wakeupParam.infoParams);
                    })
                    .catch(function () {
                        // 点击取消执行
                    });


            },
            ifjhb:function(){
                let that = this;
                //捡红包
                this.axios.post(
                    interbaseUrl + "setsail/external/externalService?service=getInteractivieIds",//根据内容id判断是否有捡红包
                    qs.stringify({
                        params: JSON.stringify({
                            contentId: this.jhb_info.contentId,
                            contentType: this.jhb_info.contentType,
                        }),
                        apiVersion: process.env.VUE_APP_SERVER_VER
                    })
                ).then((response) => {
                    //  console.log(JSON.stringify(response.data));
                    if (response.data.state == 1000) {
                        this.axios.get(
                            yaobaseUrl+ "app/yf/checklottery?wid=" + response.data.data.interactiveIds[0] + "&wheel_type=3&accesstoken=-1",//判断活动是否在进行
                        ).then((res) => {
                            console.log(res.data.msg == "ok")
                            if (res.data.msg == "ok") {
                                that.ishshow = true;
                            }
                        })
                    }
                })
            }
        }

    }
</script>

<style>
    .fl_jhb {
        width: 60px;
        position: fixed;
        bottom: 130px;
        right: 40px;
        z-index: 13333;
        display: none;
    }

    .fl_jhb img.jhb {
        width: 100%
    }

    .fl_jhb img.close_jhb {
        width: 20px;
        height: 20px;
        position: absolute;
        top: -20px;
        right: -5px;
        z-index: 23333
    }

    .ishshow {
        display: block
    }
</style>